package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.service.DeliveryWorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RefreshScope
@RestController
@RequestMapping("/DeliveryWorkerController")
public class DeliveryWorkerController {
    @Autowired
    DeliveryWorkerService deliveryWorkerService;

    @GetMapping("/listOrders")
    public CommonResult<List> getOrders() {
        return new CommonResult(200, "success", deliveryWorkerService.listOrders());
    }
    
    @GetMapping("/listAcceptOrders/{deliveryWorkerId}")
    public CommonResult<List> getAcceptOrders(@PathVariable("deliveryWorkerId") String deliveryWorkerId) {
        return new CommonResult(200, "success", deliveryWorkerService.listAcceptOrders(deliveryWorkerId));
    }

    @PostMapping("/acceptOrder/{orderId}/{deliveryWorkerId}")
    public CommonResult<Integer> acceptOrder(@PathVariable("orderId") int orderId,
                                             @PathVariable("deliveryWorkerId") String deliveryWorkerId) {
        return new CommonResult(200, "success", deliveryWorkerService.acceptOrder(orderId, deliveryWorkerId));
    }

    @PostMapping("/deliverOrder/{orderId}/{deliveryWorkerId}")
    public CommonResult<Integer> deliveringOrder(@PathVariable("orderId") int orderId,
                                                 @PathVariable("deliveryWorkerId") String deliveryWorkerId) {
        return new CommonResult(200, "success", deliveryWorkerService.deliverOrder(orderId, deliveryWorkerId));
    }
}
